package models

//import "fmt"

//	"github.com/gin-gonic/gin"

type Admission struct {
	Eno    string  `gorm:"column:eno"`
	Aname  string  `gorm:"column:aname"`
	Cname  string  `gorm:"column:cname"`
	Fscore string `gorm:"column:fscore"`
	Sscore string `gorm:"column:sscore"`
}

func GetAllAdmission(AdmissionParam map[string]interface{}) (error, []Admission, int64) {
	var AdmissionData []Admission
	page := AdmissionParam["page"].(int)
	pageSize := AdmissionParam["limit"].(int)
	searchText := AdmissionParam["searchText"].(string)
	var total int64
	err := db.Table("admission").Where("eno like ?", "%"+searchText+"%").Order("cname ASC").Count(&total).Find(&AdmissionData).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, AdmissionData, total
}

func AddAdmission(admissiondata Admission) (error, Admission) {
	err := db.Table("admission").Select("eno", "aname", "cname", "fscore", "sscore").Create(&admissiondata).Error
	return err, admissiondata
}

func UpdateAdmission(eno string, admissiondata Admission) (error, Admission) {
	err := db.Table("admission").Where("eno = ?", admissiondata.Eno).Updates(&admissiondata).Error
	return err, admissiondata
}

func DeleteAdmission(eno string) (error, Admission) {
	var admissiondata Admission
	admissiondata.Eno = eno
	err := db.Table("admission").Where("eno = ?", eno).Find(&admissiondata).Delete(Admission{}).Error
	return err, admissiondata
}

